"""
@Author  : 康帅
@Time    : 2021/3/17 14:00
@Function: 职责模式(责任链模式)：请假案列v2.0
"""


from DesignMode.DutyMode.AskForLeaveBase import Responsible, Request


class Person:
    """ 请假人 """

    def __init__(self, name):
        self.__name = name
        self.__leader = None

    def set_name(self, name):
        self.__name = name

    def get_name(self):
        return self.__name

    def set_leader(self, leader):
        self.__leader = leader

    def get_leader(self):
        return self.__leader

    def send_request(self, request):
        print("%s申请请假%d天。请假事由：%s" % (self.__name, request.get_day_off(), request.get_reason()))
        if self.__leader is not None:
            self.__leader.handler_request(request)


class Supervisor(Responsible):
    """ 主管 """

    def __init__(self, name, title):
        super().__init__(name, title)

    def _handler_request_impl(self, request):
        if request.get_day_off() <= 2:
            print("同意%s请假，签字人：%s(%s)" % (request.get_name(), self.get_name(), self.get_title()))


class DepartmentManager(Responsible):
    """ 部门总监 """

    def __init__(self, name, title):
        super().__init__(name, title)

    def _handler_request_impl(self, request):
        if request.get_day_off() > 2 and request.get_day_off() <= 5:
            print("同意%s请假，签字人：%s(%s)" % (request.get_name(), self.get_name(), self.get_title()))


class Ceo(Responsible):
    """ CEO """

    def __init__(self, name, title):
        super().__init__(name, title)

    def _handler_request_impl(self, request):
        if request.get_day_off() > 5 and request.get_day_off() <= 22:
            print("同意%s请假，签字人：%s(%s)" % (request.get_name(), self.get_name(), self.get_title()))


class Administrator(Responsible):
    """ 行政人员 """

    def __init__(self, name, title):
        super().__init__(name, title)

    def _handler_request_impl(self, request):
        print("%s的请假申请已审核，情况属实！已备案处理。处理人：%s(%s)\n" % (request.get_name(), self.get_name(), self.get_title()))


if __name__ == '__main__':
    direct_leader = Supervisor("Jack", "客户端研发部经理")
    department_leader = DepartmentManager("Kim", "技术研发部总监")
    ceo = Ceo("Helen", "智标数据ceo")
    administrator = Administrator("Nina", "行政中心总监")
    direct_leader.set_next_handler(department_leader)
    department_leader.set_next_handler(ceo)
    ceo.set_next_handler(administrator)

    sunny = Person("Sunny")
    sunny.set_leader(direct_leader)
    sunny.send_request(Request(sunny.get_name(), 1, "参加MDCC大会"))

    tony = Person("Tony")
    tony.set_leader(direct_leader)
    tony.send_request(Request(tony.get_name(), 5, "家里有事"))

    pony = Person("Pony")
    pony.set_leader(direct_leader)
    pony.send_request(Request(pony.get_name(), 15, "学术研究"))
